// hyb_yl/mysubpages/pages/docorder/docorder.js
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    page:0,
    pagesize:10,
    list:[],
    typs:"",
    y_id:"",
  },
  
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
   var y_id = options.y_id;
    var typs=options.typs;
    if(typs == 'yishen')
    {
      var title = '已审';
    }else if(typs == 'shenhe')
    {
      var title = '审核';
    }
    wx.setNavigationBarTitle({
      title: title + '订单'
    })
    that.setData({
      y_id:y_id,
      typs:typs,
    })
    // that.getOrder();
  },
  getOrder(){
    var that = this;
    var typs = that.data.typs;
    var y_id = that.data.y_id;
    app.util.request({
      'url':"enret/wxapp/yaoshi.order_list",
      data:{
        y_id:y_id,
        page:that.data.page,
        pagesize:that.data.pagesize,
        typs:typs
      },
      success:function(res){
        var page = that.data.page + 1;
        that.setData({
          page:page,
          list:that.data.list.concat(res.data)
        })
      }
    })
  },
  // 审核药品
  shenhe:function(e){
    var that = this;
    var id = e.currentTarget.dataset.id;
    var status = e.currentTarget.dataset.status;
    wx.showModal({
      title: '提示',
      content:"是否确认审核改订单",
      success:function(con)
      {
        if(con.confirm)
        {
          app.util.request({
            'url':"entry/wxapp/yaoshi.shenhe_order",
            data:{
              id:id,
              y_id:that.data.y_id,
              status:status
            },
            success:function(res)
            {
              wx.showToast({
                title: '审核成功',
              })
              that.setData({
                page:0,
                list:[],
              })
              setTimeout(() => {
                that.getOrder();
              }, 500);
            }
          })
        }
      }
    })
  },
  // 查看订单详情
  todetail:function(e){
    var that = this;
    var id = e.currentTarget.dataset.id
    var orderStatus = e.currentTarget.dataset.orderstatus
    wx.navigateTo({
      url: '/hyb_yl/yaoshi/pages/chufangjianyi/chufangjianyi?id=' + id + '&orderStatus=' + orderStatus + '&xufang=1&y_id='+that.data.y_id,
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var that = this
    that.setData({
      page:0,
      list:[]
    })
    that.getOrder();
  },
  
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    this.getOrder();
  },
 
  
 
  
})